package com.fast.common.util;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

public class NumberUtil extends NumberUtils {

	private static DecimalFormat df = new DecimalFormat("0.00");

	public static BigDecimal format(BigDecimal amt) {
		if (amt == null) {
			return new BigDecimal(0);
		}
		return new BigDecimal(df.format(amt));

	}

	public static boolean isMobile(String mobile) {
		if (StringUtils.isEmpty(mobile)) {
			return false;
		}
		String reg = "^1[3|5|8|7](\\d{9,10})$";
		Pattern pattern = Pattern.compile(reg);
		Matcher matcher = pattern.matcher(mobile);
		if (matcher.find()) {
			return true;
		}
		return false;
	}

	public static boolean isNumber( String str ) {
		String reg = "^\\d$";
		Pattern pattern = Pattern.compile(reg);
		Matcher matcher = pattern.matcher(str);
		if (matcher.find()) {
			return true;
		}
		return false;
	}

	public static boolean isEmail( String email ){
		if( StringUtils.isBlank(email)){
			return false;
		}
		String reg = "^(\\d|\\w|\\W|\\.{0,1}){1,}@(foxmail|126|163|qq|gmail).(com|cn|com.cn)$";
		Pattern pattern = Pattern.compile(reg);
		Matcher matcher = pattern.matcher(email);
		if (matcher.find()) {
			return true;
		}
		
//		int index = email.indexOf("@");
//		if(index > 0 ){
//			return true;
//		}
		return false;
	}
	public static void main(String[] args) {
		//		System.out.println(format(new BigDecimal(12222.1)));
		System.out.println(isEmail("fx.windy@foxmail.com"));
		
	}
}
